#include "gofgame/dungeonkeeper/unitmanagerscene/UnitManagerView.h"
#include "gofgame/common/ui/DockLayout.h"
#include "gofgame/common/ui/DockLayoutData.h"
#include "gofgame/common/ui/UIShellLayer.h"
#include "gofgame/common/graphics/LinearGradientBrush.h"
#include "gofgame/common/graphics/HornedTextureBrush.h"
#include <string.h>
#include "gofgame/dungeonkeeper/loadingscene/LoadingScene.h"

using namespace gofgame::dungeonkeeper::unitmanagerscene;
using namespace gofgame::common::ui;
using namespace gofgame::dungeonkeeper::ui;
using namespace gofgame::dungeonkeeper::game;
using namespace gofgame::dungeonkeeper::loadingscene;
using namespace babyfish;

UnitManagerView::UnitManagerView() {
	this->startButton.initialize();
}

bool UnitManagerView::init() {
	if(!Container::init()){
		return false;
	}
	this->setLayout(new DockLayout(20));

	Ref<Container> container;
	container.initialize();
	container->init();
	container->setHeight(70);
	container->setLayout(new DockLayout());
	container->setLayoutData(new DockLayoutData(DockStyle_Bottom));
	this->addChild(container);


	this->startButton->setWidth(150);
	this->startButton->setBackgroundBrush(
		new HornedTextureBrush(
		CCSize(10, 10),
		CCTextureCache::sharedTextureCache()->addImage(
		"gofgame/dungeonkeeper/ui/upgrade_button.png"
		),
		Brush::white()
		)
		);
	this->startButton->setPressedBackgroundBrush(
		new HornedTextureBrush(
		CCSize(10, 10),
		CCTextureCache::sharedTextureCache()->addImage(
		"gofgame/dungeonkeeper/ui/upgrade_button.png"
		),
		new LinearGradientBrush(0, 0, 0, 0, 1, 0, 0, 1)
		)
		);
	this->startButton->setLayoutData(new DockLayoutData(DockStyle_Right));
	container->addChild(this->startButton);
	this->startButton->click() += event_handler<ComponentEventArgs>(
		this, &UnitManagerView::startButton_click);
	return true;
}

void UnitManagerView::startButton_click(void *sender, ComponentEventArgs &e){
	LoadingScene *loadingscene = LoadingScene::create();
	CCDirector::sharedDirector()->replaceScene(loadingscene);
}